package com.solome.app;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.assets.AssetManager;
import com.solome.app.lication.FirstPage;
import com.solome.base.Logger;
import com.solome.logic.Overlap2d;
import com.solome.net.ByteArray;
import com.solome.net.HTTP;
import com.solome.net.NetCallback;
import com.solome.oc.CodeUi;
import com.solome.util.FontFactory;
import com.solome.util.InvokeFactory;
import com.solome.util.ZipCacheObject;
import com.solome.util.csv.CsvTest;

public class App extends Game {
	public static AssetManager manager; // 资源管理

	@Override
	public void create() {
		// Connection connection = new Connection();
		// connection.setConnect(Connect.SOCKET);
		// connection.connectOperate("120.26.118.91", 26999);
		// Executors.newSingleThreadExecutor().execute(connection);
		manager = new AssetManager();
		this.setScreen(new FirstPage(this));
		App self = this;

		// HTTP.send(new ByteArray(12345), new NetCallback() {
		//
		// @Override
		// public void callback(GameStatus status) throws IOException {
		// // TODO Auto-generated method stub
		// if (status.isSuccess()) {
		// BufferedReader in = new BufferedReader(
		// new InputStreamReader((DataInputStream) status
		// .getBindingObject(), "utf-8"));
		// String ln;
		// // Array<String> array = new Array<String>();
		// StringBuffer stringBuffer = new StringBuffer();
		// while ((ln = in.readLine()) != null) {
		// stringBuffer.append(ln);
		// }
		//
		// byte[] bs = stringBuffer.toString().getBytes("UTF-8");
		// ZipCacheObject cacheObject = new ZipCacheObject(bs);
		// CodeUi codeUi = (CodeUi) cacheObject.getObject();
		// codeUi.setGame(self);
		// self.setScreen(codeUi);
		// } else {
		// // System.out.println("......." + status.getMessage());
		// Gdx.app.postRunnable(new Runnable() {
		// @Override
		// public void run() {
		// self.setScreen(new CodeUi(self));
		// }
		// });
		// }
		//
		// }
		// });
		CsvTest model = new CsvTest();
		try {
			model.load();
			Logger.error(this, "数据长度=" + model.length());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public static AssetManager getManager() {
		return manager;
	}

	public boolean paused;

	@Override
	public void render() {
		if (paused) {
			return;
		}
		InvokeFactory.getInstance().invoke();
		super.render();
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		super.dispose();
		if (this.getScreen() != null) {
			this.getScreen().dispose();
		}
		FontFactory.getInstance().dispose();
		InvokeFactory.getInstance().dispose();
	}
}
